package com.event.management.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.event.management.backend.domain.Event;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;

/**
 * 活动Mapper接口
 */
@Mapper
public interface EventMapper extends BaseMapper<Event> {
    
    /**
     * 查询活动关联的票种数量
     * @param eventId 活动ID
     * @return 票种数量
     */
    @Select("SELECT COUNT(1) FROM tickets WHERE event_id = #{eventId} AND is_deleted = 0")
    Integer selectTicketCountByEventId(@Param("eventId") Long eventId);
    
    /**
     * 统计活跃活动数量（未删除的）
     * @return 活动数量
     */
    @Select("SELECT COUNT(1) FROM events WHERE is_deleted = 0")
    Integer countActiveEvents();
    
    /**
     * 统计指定时间后创建的活动数量
     * @param dateTime 时间点
     * @return 活动数量
     */
    @Select("SELECT COUNT(1) FROM events WHERE created_at >= #{dateTime} AND is_deleted = 0")
    Integer countEventsCreatedAfter(@Param("dateTime") LocalDateTime dateTime);
    
    /**
     * 增加活动浏览量
     * @param eventId 活动ID
     */
    @Select("UPDATE events SET view_count = view_count + 1 WHERE id = #{eventId}")
    void incrementViewCount(@Param("eventId") Long eventId);
} 